package com.hifar.test.api.model;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 详细错误信息类
 * 提供更丰富的错误详情
 */
public class DetailedErrorInfo {
    
    private String errorId;
    private String errorCode;
    private String errorMessage;
    private String errorSuggestion;
    private String errorCategory;
    private String errorSeverity;
    private String operation;
    private String dataId;
    private String fieldName;
    private Object fieldValue;
    private String stackTrace;
    private String rootCause;
    private Map<String, Object> context;
    private LocalDateTime timestamp;
    private String requestId;
    private String clientIp;
    private String userId;
    private String sessionId;
    
    public DetailedErrorInfo() {
        this.timestamp = LocalDateTime.now();
        this.context = new HashMap<>();
    }
    
    public DetailedErrorInfo(String errorCode, String errorMessage) {
        this();
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }
    
    /**
     * 添加上下文信息
     */
    public void addContext(String key, Object value) {
        this.context.put(key, value);
    }
    
    /**
     * 获取完整的错误描述
     */
    public String getFullDescription() {
        StringBuilder sb = new StringBuilder();
        sb.append("错误ID: ").append(errorId).append("\n");
        sb.append("错误码: ").append(errorCode).append("\n");
        sb.append("错误信息: ").append(errorMessage).append("\n");
        sb.append("错误分类: ").append(errorCategory).append("\n");
        sb.append("错误级别: ").append(errorSeverity).append("\n");
        sb.append("操作类型: ").append(operation).append("\n");
        sb.append("数据ID: ").append(dataId).append("\n");
        if (fieldName != null) {
            sb.append("字段名: ").append(fieldName).append("\n");
        }
        if (fieldValue != null) {
            sb.append("字段值: ").append(fieldValue).append("\n");
        }
        if (rootCause != null) {
            sb.append("根本原因: ").append(rootCause).append("\n");
        }
        sb.append("时间戳: ").append(timestamp).append("\n");
        if (requestId != null) {
            sb.append("请求ID: ").append(requestId).append("\n");
        }
        if (clientIp != null) {
            sb.append("客户端IP: ").append(clientIp).append("\n");
        }
        if (userId != null) {
            sb.append("用户ID: ").append(userId).append("\n");
        }
        return sb.toString();
    }
    
    // Getters and Setters
    public String getErrorId() {
        return errorId;
    }
    
    public void setErrorId(String errorId) {
        this.errorId = errorId;
    }
    
    public String getErrorCode() {
        return errorCode;
    }
    
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public String getErrorSuggestion() {
        return errorSuggestion;
    }
    
    public void setErrorSuggestion(String errorSuggestion) {
        this.errorSuggestion = errorSuggestion;
    }
    
    public String getErrorCategory() {
        return errorCategory;
    }
    
    public void setErrorCategory(String errorCategory) {
        this.errorCategory = errorCategory;
    }
    
    public String getErrorSeverity() {
        return errorSeverity;
    }
    
    public void setErrorSeverity(String errorSeverity) {
        this.errorSeverity = errorSeverity;
    }
    
    public String getOperation() {
        return operation;
    }
    
    public void setOperation(String operation) {
        this.operation = operation;
    }
    
    public String getDataId() {
        return dataId;
    }
    
    public void setDataId(String dataId) {
        this.dataId = dataId;
    }
    
    public String getFieldName() {
        return fieldName;
    }
    
    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }
    
    public Object getFieldValue() {
        return fieldValue;
    }
    
    public void setFieldValue(Object fieldValue) {
        this.fieldValue = fieldValue;
    }
    
    public String getStackTrace() {
        return stackTrace;
    }
    
    public void setStackTrace(String stackTrace) {
        this.stackTrace = stackTrace;
    }
    
    public String getRootCause() {
        return rootCause;
    }
    
    public void setRootCause(String rootCause) {
        this.rootCause = rootCause;
    }
    
    public Map<String, Object> getContext() {
        return context;
    }
    
    public void setContext(Map<String, Object> context) {
        this.context = context;
    }
    
    public LocalDateTime getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(LocalDateTime timestamp) {
        this.timestamp = timestamp;
    }
    
    public String getRequestId() {
        return requestId;
    }
    
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
    
    public String getClientIp() {
        return clientIp;
    }
    
    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getSessionId() {
        return sessionId;
    }
    
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }
    
    @Override
    public String toString() {
        return "DetailedErrorInfo{" +
                "errorId='" + errorId + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                ", errorCategory='" + errorCategory + '\'' +
                ", errorSeverity='" + errorSeverity + '\'' +
                ", operation='" + operation + '\'' +
                ", dataId='" + dataId + '\'' +
                ", timestamp=" + timestamp +
                '}';
    }
}
